package com.yunche.yunchebusiness.base

import android.app.Activity
import android.os.Build

/**
 * Create by Crcker on 2018/12/20 11:07
 * Email: Crcker@163.com
 */


object ActivityManager {
    private val mActivityList: ArrayList<Activity> = ArrayList<Activity>()


    fun pushActivity(act: Activity) {
        mActivityList.add(act)
    }

    fun popActivity(act: Activity) {
        if (!mActivityList.isEmpty() || mActivityList.contains(act)) {
            mActivityList.remove(act)
        }
    }

    fun exitApp() {
        if (mActivityList.isNotEmpty()) {
            for (activity in mActivityList) {
                if (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                        !activity.isDestroyed
                    } else {
                        TODO("VERSION.SDK_INT < JELLY_BEAN_MR1")
                    }
                ) {
                    activity.finish()
                }
            }
        }
        //强制杀死
        android.os.Process.killProcess(android.os.Process.myPid())
        System.exit(0)
    }

}